VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "ClsDetalle"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Public WithEvents orset As ClsRecordset
Attribute orset.VB_VarHelpID = -1

Public Event DataChanged()

Public codigo As String
Public codServicio As String
Public numero As Integer
Public nombre As String

Private Sub Class_Initialize()
    Set orset = New ClsRecordset
    orset.setCampos dbCampos(dta)
    orset.setTablas Array(dta)
End Sub
Private Sub Class_Terminate()
    Set orset = Nothing
End Sub
Public Sub consulta()
    orset.consulta
End Sub
Public Sub consultaDatos(codig As String)
    orset.consulta Array(dta_id & "=" & codig)
    orset.CierraRec
End Sub
Public Sub consultaDeMov(codMovim As String)
    orset.consultaGral , Array(dta, tdt), _
                       Array(tdt_dta_id & "=" & dta_id, _
                             tdt_tra_id & "='" & codMovim & "'")
End Sub
Public Sub consultaServicio(serCod As String)
    orset.consulta Array(dta_ser_id & "=" & serCod), _
                   Array(dta_numero & " ASC")
End Sub
Public Sub consultaTipoServicio(tseCod As String)
    'orset.consulta Array(dta_tse_id & "=" & tseCod), _
                   Array(dta_numero & " ASC")
End Sub
Public Sub consultaXNumeroYServicio(numDetalle As String, serCod As String)
    orset.consulta Array(dta_numero & ">=" & numDetalle, dta_ser_id & "=" & serCod), _
                   Array(dta_numero & " ASC")
End Sub
Public Sub consultaInferiores(codig As String)
    orset.consulta Array(dta_id & "<=" & codig), Array(dta_id & " DESC")
End Sub

Public Sub consultaFactMasivaSiguiente(tipoServicioCod As String)
    'solo para asociados : ser_tse_id = 1
    Dim sqGenerados As ClsSQL
    Set sqGenerados = New ClsSQL
    sqGenerados.setCampos Array(gva_dta_id)
    sqGenerados.setTablas Array(gva)
    
    orset.consultaGral , Array(ser, dta), _
                       Array(dta_ser_id & "=" & ser_id, _
                             ser_tse_id & "=" & tipoServicioCod, _
                             dta_id & " NOT IN (" & sqGenerados.sSelect & ")"), _
                       Array(ser_id, dta_numero)
End Sub

Public Sub consultaServicioNoGeneradosXVentaAutomatica(serCod As String)
    'consulta los detalles que se generaron
    Dim sqgenvau As ClsSQL
    Set sqgenvau = New ClsSQL
    sqgenvau.setCampos Array(gva_dta_id)
    sqgenvau.setTablas Array(gva)
    sqgenvau.setCondiciones Array(gva_ser_id & "=" & serCod)
    'para quitarlos de la busqueda
    orset.consulta Array(dta_ser_id & "=" & serCod, _
                         dta_id & " not in (" & sqgenvau.sSelect & ")"), _
                   Array(dta_numero & " ASC")
End Sub

Public Sub consultaNoVendidosCliente(serCod As String, clicod As String)
    'primero busca el detalle minimo de venta
    Dim dtaMinimo As String
    Dim cliVau As New ClsCaractGrvCli
    'cliVau.consultaCliente clicod, servicio.codTipo
    If cliVau.orset.numRegistros > 0 Then
        dtaMinimo = cliVau.codDetalle
    Else
        dtaMinimo = "0"
    End If
    'consulta los detalles que se generaron
    Dim condic As Variant
    Dim sqvencli As ClsSQL
    Set sqvencli = New ClsSQL
    sqvencli.setCampos Array(dta_id)
    sqvencli.setTablas Array(tra, dta, tdt)
    sqvencli.setCondiciones Array(tra_id & "=" & tdt_tra_id, _
                       dta_id & "=" & tdt_dta_id, _
                       dta_ser_id & "=" & serCod, _
                       tra_cli_id & "='" & clicod & "'")
    'para quitarlos de la busqueda
    orset.consulta Array(dta_ser_id & "=" & serCod, _
                         dta_id & " not in (" & sqvencli.sSelect & ")", _
                         dta_id & ">=" & dtaMinimo), _
                   Array(dta_numero & " ASC")
End Sub

Private Sub Reload_members()
    With orset
        codigo = .getDato(dta_id)
        codServicio = .getDato(dta_ser_id)
        numero = .getDato(dta_numero)
        nombre = .getDato(dta_nombre)
    End With
End Sub
Public Sub Nuevo(newSerId As String, newNumero As String, newNombre As String)
    orset.sInsert Array("", newSerId, newNumero, newNombre)
End Sub
Public Sub Modificar(codig As String, newSerId As String, newNumero As String, newNombre As String)
    orset.sUpdate Array(codig, newSerId, newNumero, newNombre)
End Sub
Public Sub Borrar(codig As String)
    orset.sDelete Array(dta_id & "=" & codig)
End Sub
Public Sub llenaCombo(cajaCombo As ComboBox, serCod As String, conCodigo As Boolean, conNumero As Boolean)
    Dim i As Integer
    Me.consultaServicio serCod
    i = 0
    cajaCombo.Clear
    If conCodigo Then
        While orset.CanMoveNext
            cajaCombo.AddItem Me.codigo & " - " & Me.nombre
            cajaCombo.ItemData(i) = codigo
            orset.MoveNext
            i = i + 1
        Wend
    Else
        If conNumero Then
            While orset.CanMoveNext
                cajaCombo.AddItem Me.numero & " - " & nombre
                cajaCombo.ItemData(i) = codigo
                orset.MoveNext
                i = i + 1
            Wend
        Else
            While orset.CanMoveNext
                cajaCombo.AddItem nombre
                cajaCombo.ItemData(i) = codigo
                orset.MoveNext
                i = i + 1
            Wend
        End If
    End If
    If cajaCombo.ListCount > 0 Then
        cajaCombo.ListIndex = 0
    End If
    orset.CierraRec
End Sub
Private Sub orset_DataChanged()
    Reload_members
End Sub
